#include "datefield.h"
#include <QDateEdit>
#include <qplugin.h>

DateField::DateField()
{
}

QWidget *DateField::createDelegate(const QVariantMap &properties)
{
    QDateEdit *edit = new QDateEdit();

    if (properties.contains("min"))
        edit->setMinimumDate(properties["min"].toDate());

    if (properties.contains("max"))
        edit->setMaximumDate(properties["max"].toDate());

    return edit;
}

void DateField::setEditable(QWidget *delegate, bool editable)
{
    QDateEdit *edit = (QDateEdit *)delegate;
    edit->setReadOnly(!editable);
}

QVariant DateField::data(QWidget *delegate) const
{
    QDateEdit *edit = (QDateEdit *)delegate;
    return edit->date();
}

void DateField::setData(QWidget *delegate, const QVariant &data)
{
    QDateEdit *edit = (QDateEdit *)delegate;
    edit->setDate(data.toDate());
}

void DateField::clear(QWidget *delegate)
{
    QDateEdit *edit = (QDateEdit *)delegate;
    edit->clear();
}

Q_EXPORT_PLUGIN2(date-field, DateField)
